<?php
//
// +---------------------------------------------------------------------------------+
// | Package: EezeeSite Core                                                         |
// +---------------------------------------------------------------------------------+
// | Copyright (C) 2006  EezeeSite Development Team                                  |
// +---------------------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or                   |
// | modify it under the terms of the GNU General Public License                     |
// | as published by the Free Software Foundation; either version 2                  |
// | of the License, or (at your option) any later version.                          |
// |                                                                                 |
// | This program is distributed in the hope that it will be useful,                 |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                  |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                   |
// | GNU General Public License for more details.                                    |
// |                                                                                 |
// | You should have received a copy of the GNU General Public License               |
// | along with this program; if not, write to the Free Software                     |
// | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. |
// +---------------------------------------------------------------------------------+
// | Author: Mayukh De <mayukhde@gmail.com>                                          |
// +---------------------------------------------------------------------------------+
//

$installDir = explode($_SERVER['DOCUMENT_ROOT'], dirname($_SERVER['SCRIPT_FILENAME']));
$theme = (array_key_exists('theme', $localSettings) && !empty($localSettings['theme'])) ? $localSettings['theme'] : 'clean_theme';
$protocol = (isset($localSettings['secure']) && $localSettings['secure'] = 'YES') ? 'https' : 'http';

require_once 'global.config.php';
require_once 'global.include.php';

define(ES_INSTALL_DIR, dirname($_SERVER['SCRIPT_FILENAME']));
define(ES_BASE_URL, $protocol.'://'.$_SERVER['HTTP_HOST'].$installDir[1].'/');
define(ES_ASSETS_URL, ES_BASE_URL.'_assets/');
define(ES_JS_URL, ES_ASSETS_URL.'js/');
define(ES_ICO_URL, ES_ASSETS_URL.'icons/');
define(ES_THEME_URL, ES_ASSETS_URL.$theme.'/');
define(ES_CONFIG_FILE, $GLOBALS['ES']['CNFDIR'].'/'.md5(ES_BASE_URL).'.config.php');

if (file_exists(ES_CONFIG_FILE)) {
    require_once ES_CONFIG_FILE;
}

$ESMail =& Mail::factory(strtolower($GLOBALS['ES']['EMAILPROTOCOLS']['MAIL']), $GLOBALS['ES']['EMAILSETTINGS']['MAIL']);

if (is_array($GLOBALS['ES']['CLIENTCONF'])) {
    define(ES_TBL_PRE, $GLOBALS['ES']['CLIENTCONF']['table_prefix'].'_');
    require_once 'dbschema.config.php';
    $DBPort = ($GLOBALS['ES']['CLIENTCONF']['db_port'] && !empty($GLOBALS['ES']['CLIENTCONF']['db_port'])) ? ':'.$GLOBALS['ES']['CLIENTCONF']['db_port'] : null;
    $dsn = strtolower($GLOBALS['ES']['CLIENTCONF']['db_type']).'://'.$GLOBALS['ES']['CLIENTCONF']['db_user_name'].':'.$GLOBALS['ES']['CLIENTCONF']['db_password'].'@'.$GLOBALS['ES']['CLIENTCONF']['db_host'].$DBPort.'/'.$GLOBALS['ES']['CLIENTCONF']['db_name'];
    $ESDB = DB::connect($dsn);
    $ESAuth = new ESAuthentication();
    $ESPerms = new ESPerms($ESDB);
}

$ESDisplay = new ESDisplay($localSettings['lang']);
$ESResponse = new ESResponse();
$ESController = new ESController();
$ESWebForms = new ESWebForms();
$ESAJAX = new ESAJAX();

if ($_GET['logo'] == 'true') {
    $ESResponse->sendHTTPHeader('JPEG');
    echo $GLOBALS['ES']['ESLOGO'];
    die;
}

if (basename($_SERVER['SCRIPT_NAME']) != 'server'.ES_FILE_EXTN) {
    $checkPoint = (isset($_GET['sysCheck']) && $_GET['sysCheck'] = 'all') ? null : 'installLock';
    $ESCoreCheck = new ESSystemCoreCheck($ESResponse);
    if (basename($_SERVER['SCRIPT_NAME']) == 'admin'.ES_FILE_EXTN && isset($_GET['mode']) && $_GET['mode'] = 'install') {
        require_once $GLOBALS['ES']['INCDIR'].'/admin_mode_install.inc.php';
    } else {
        $ESDisplay->assign('INITESCLIENT', true);
        $ESDisplay->assign('AUTHSTATUS', true);
        $LOGINFORM = $ESWebForms->buildForm('logInForm', array('FORMONEVENTACTION' => array('onsubmit' => 'logIn(this); return false;')));
        $PASSWORDREMINDERFORM = $ESWebForms->buildForm('passwordReminderForm', array('FORMONEVENTACTION' => array('onsubmit' => 'passwordReminder(this); return false;')));
        $ESDisplay->assign('LOGINFORM', $LOGINFORM);
        $ESDisplay->assign('PASSWORDREMINDERFORM', $PASSWORDREMINDERFORM);
        $inc = $ESController->getIncFileToLoad();
        require_once $inc;
    }
	if (!defined('ES_NO_CACHE') && $GLOBALS['ES']['ALLOWCLIENT']['USECACHEING']) {
	    if (is_array($GLOBALS['ES']['CLIENTCONF']) && ($GLOBALS['ES']['CLIENTCONF']['use_cache'] == '1')) {
		    /*$ESDisplay->caching        = true;
		    $ESDisplay->cache_lifetime = $GLOBALS['ES']['CACHELIFETIME'];
	        $JPCACHE_TYPE          = 'file';
		    $JPCACHE_DEBUG         = ($GLOBALS['ES']['DEBUGMODE']) ? 1 : 0;
		    $JPCACHE_DIR           = $ESDisplay->cache_dir;
		    $JPCACHE_ON            = 1;
		    $JPCACHE_TIME          = $GLOBALS['ES']['CACHELIFETIME'];
            $JPCACHE_IGNORE_DOMAIN = 1;
            $JPCACHE_USE_GZIP      = 1;
            $JPCACHE_POST          = 0;
            $JPCACHE_GC            = 1;
            $JPCACHE_GZIP_LEVEL    = 9;
            $JPCACHE_CLEANKEYS     = 0;
		    $JPCACHE_FILEPREFIX    = 'es-jpc-';
	        require_once 'jpcache/jpcache.php';*/
		}
	}
    $ESDisplay->display(ES_DISPLAY_TPL);
}

?>